
#ifndef PHYSICALDISK_H_
#define PHYSICALDISK_H_

#include "SuperBlock.h"
#include "FreeAddressesBlock.h"
#include <vector>
#include <map>
#include "../lowLevel/Inode.h"


using namespace std;

class PhysicalDisk {

private:
	int fd;
	SuperBlock* superBlock;
	/* calculates the addresses of the blocks that will contain other free blocks addresses */
	void writeBlocksOfFreeAddresses(vector<FreeAddressesBlock*>& addressBlocks);
	vector<FreeAddressesBlock*> allocateBlocksForFreeBlocksAddresses (int numOfAddressesInBlock, int dataBlockSize);
	vector<FreeAddressesBlock*> allocateBlocksForFreeInodesAddresses (int numOfAddressesInBlock, int dataBlockSize, int numberOfInodes);
	vector<int> calcFreeAddressesBlocks(int numOfAddresses);
	vector<int> calcFreeINodesBlocks(int numOfAddresses, int dataBlockSize);
	FreeAddressesBlock* makeObjectAddressesBlock(vector<int> & freeAddressesBlocks,
			int & dataBlockSize, int & freeInodesCounter, int & freeBlocksOffset, int objectSize);

    void loadBlock(char* block);

public:

	/* C'tor - is called when a FILE_SYS already exists*/
	PhysicalDisk();

	/* C'tor - is called when a FILE_SYS doesn't exist*/
	PhysicalDisk(int diskSizeInBlocks, int dataBlockSize, int numberOfInodes);

	virtual ~PhysicalDisk();

	int getFileDesc();

	int getBlockSize();

	int getNumOfInodes();

	int allocateBlock();

	void freeBlock(int blockOffset);

	int allocateInode();

	void freeInode(int inodeOffset);

	void main();


};

#endif /* PHYSICALDISK_H_ */
